{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## install package"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Processing ./zh_core_web_sm-2.0.3.tar.gz\n",
      "Requirement already satisfied: spacy>=2.0.0a18 in /home/howl/.local/lib/python3.5/site-packages (from zh-core-web-sm==2.0.3) (2.0.12)\n",
      "Requirement already satisfied: dill<0.3,>=0.2 in /home/howl/.local/lib/python3.5/site-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (0.2.8.2)\n",
      "Requirement already satisfied: thinc<6.11.0,>=6.10.3 in /home/howl/.local/lib/python3.5/site-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (6.10.3)\n",
      "Requirement already satisfied: numpy>=1.7 in /usr/local/lib/python3.5/dist-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (1.14.2)\n",
      "Requirement already satisfied: plac<1.0.0,>=0.9.6 in /home/howl/.local/lib/python3.5/site-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (0.9.6)\n",
      "Requirement already satisfied: requests<3.0.0,>=2.13.0 in /usr/local/lib/python3.5/dist-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (2.18.4)\n",
      "Requirement already satisfied: cymem<1.32,>=1.30 in /home/howl/.local/lib/python3.5/site-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (1.31.2)\n",
      "Requirement already satisfied: ujson>=1.35 in /home/howl/.local/lib/python3.5/site-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (1.35)\n",
      "Requirement already satisfied: regex==2017.4.5 in /home/howl/.local/lib/python3.5/site-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (2017.4.5)\n",
      "Requirement already satisfied: murmurhash<0.29,>=0.28 in /home/howl/.local/lib/python3.5/site-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (0.28.0)\n",
      "Requirement already satisfied: preshed<2.0.0,>=1.0.0 in /home/howl/.local/lib/python3.5/site-packages (from spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (1.0.1)\n",
      "Requirement already satisfied: msgpack<1.0.0,>=0.5.6 in /home/howl/.local/lib/python3.5/site-packages (from thinc<6.11.0,>=6.10.3->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (0.5.6)\n",
      "Requirement already satisfied: tqdm<5.0.0,>=4.10.0 in /home/howl/.local/lib/python3.5/site-packages (from thinc<6.11.0,>=6.10.3->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (4.24.0)\n",
      "Requirement already satisfied: six<2.0.0,>=1.10.0 in /usr/lib/python3/dist-packages (from thinc<6.11.0,>=6.10.3->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (1.10.0)\n",
      "Requirement already satisfied: msgpack-numpy<1.0.0,>=0.4.1 in /home/howl/.local/lib/python3.5/site-packages (from thinc<6.11.0,>=6.10.3->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (0.4.3.1)\n",
      "Requirement already satisfied: wrapt<1.11.0,>=1.10.0 in /home/howl/.local/lib/python3.5/site-packages (from thinc<6.11.0,>=6.10.3->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (1.10.11)\n",
      "Requirement already satisfied: cytoolz<0.10,>=0.9.0 in /home/howl/.local/lib/python3.5/site-packages (from thinc<6.11.0,>=6.10.3->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (0.9.0.1)\n",
      "Requirement already satisfied: idna<2.7,>=2.5 in /usr/local/lib/python3.5/dist-packages (from requests<3.0.0,>=2.13.0->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (2.6)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.5/dist-packages (from requests<3.0.0,>=2.13.0->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (2018.4.16)\n",
      "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.5/dist-packages (from requests<3.0.0,>=2.13.0->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (3.0.4)\n",
      "Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/local/lib/python3.5/dist-packages (from requests<3.0.0,>=2.13.0->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (1.22)\n",
      "Requirement already satisfied: toolz>=0.8.0 in /home/howl/.local/lib/python3.5/site-packages (from cytoolz<0.10,>=0.9.0->thinc<6.11.0,>=6.10.3->spacy>=2.0.0a18->zh-core-web-sm==2.0.3) (0.9.0)\n",
      "Building wheels for collected packages: zh-core-web-sm\n",
      "  Running setup.py bdist_wheel for zh-core-web-sm ... \u001b[?25ldone\n",
      "\u001b[?25h  Stored in directory: /home/howl/.cache/pip/wheels/04/63/ec/a66252a0376a1953722cb70a85c50aa4836311eca4d69f75f3\n",
      "Successfully built zh-core-web-sm\n",
      "Installing collected packages: zh-core-web-sm\n",
      "  Found existing installation: zh-core-web-sm 2.0.2\n",
      "    Uninstalling zh-core-web-sm-2.0.2:\n",
      "      Successfully uninstalled zh-core-web-sm-2.0.2\n",
      "Successfully installed zh-core-web-sm-2.0.3\n",
      "\u001b[33mYou are using pip version 10.0.1, however version 18.0 is available.\n",
      "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install -q https://github.com/howl-anderson/Chinese_models_for_SpaCy/releases/download/v2.2.X-0.1.0/zh_core_web_sm-0.1.0.tar.gz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install -q pandas\n",
    "!pip install -q jieba\n",
    "!pip install -q tabulate"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## import packages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from spacy import displacy\n",
    "from tabulate import tabulate\n",
    "import pandas as pd\n",
    "\n",
    "import zh_core_web_sm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## load models"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "nlp = zh_core_web_sm.load()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## parse doc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Building prefix dict from the default dictionary ...\n",
      "Loading model from cache /tmp/jieba.cache\n",
      "Loading model cost 0.435 seconds.\n",
      "Prefix dict has been built successfully.\n"
     ]
    }
   ],
   "source": [
    "doc = nlp(\"王小明在北京的清华大学读书\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## print doc's attributes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text</th>\n",
       "      <th>lemma_</th>\n",
       "      <th>pos_</th>\n",
       "      <th>tag_</th>\n",
       "      <th>dep_</th>\n",
       "      <th>shape_</th>\n",
       "      <th>is_alpha</th>\n",
       "      <th>is_stop</th>\n",
       "      <th>has_vector</th>\n",
       "      <th>ent_iob_</th>\n",
       "      <th>ent_type_</th>\n",
       "      <th>vector_norm</th>\n",
       "      <th>is_oov</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>王小明</td>\n",
       "      <td>王小明</td>\n",
       "      <td>X</td>\n",
       "      <td>NNP</td>\n",
       "      <td>nsubj</td>\n",
       "      <td>xxx</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>B</td>\n",
       "      <td>PERSON</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>在</td>\n",
       "      <td>在</td>\n",
       "      <td>VERB</td>\n",
       "      <td>VV</td>\n",
       "      <td>case</td>\n",
       "      <td>x</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>O</td>\n",
       "      <td></td>\n",
       "      <td>6.573987</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>北京</td>\n",
       "      <td>北京</td>\n",
       "      <td>X</td>\n",
       "      <td>NNP</td>\n",
       "      <td>nmod</td>\n",
       "      <td>xx</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>B</td>\n",
       "      <td>GPE</td>\n",
       "      <td>12.769391</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>的</td>\n",
       "      <td>的</td>\n",
       "      <td>PART</td>\n",
       "      <td>DEC</td>\n",
       "      <td>case:dec</td>\n",
       "      <td>x</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>O</td>\n",
       "      <td></td>\n",
       "      <td>6.886564</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>清华大学</td>\n",
       "      <td>清华大学</td>\n",
       "      <td>X</td>\n",
       "      <td>NNP</td>\n",
       "      <td>obl</td>\n",
       "      <td>xxxx</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>B</td>\n",
       "      <td>ORG</td>\n",
       "      <td>18.842812</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>读书</td>\n",
       "      <td>读书</td>\n",
       "      <td>VERB</td>\n",
       "      <td>VV</td>\n",
       "      <td>ROOT</td>\n",
       "      <td>xx</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>O</td>\n",
       "      <td></td>\n",
       "      <td>18.138533</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   text lemma_  pos_ tag_      dep_ shape_  is_alpha  is_stop  has_vector  \\\n",
       "0   王小明    王小明     X  NNP     nsubj    xxx      True    False       False   \n",
       "1     在      在  VERB   VV      case      x      True     True        True   \n",
       "2    北京     北京     X  NNP      nmod     xx      True    False        True   \n",
       "3     的      的  PART  DEC  case:dec      x      True     True        True   \n",
       "4  清华大学   清华大学     X  NNP       obl   xxxx      True    False        True   \n",
       "5    读书     读书  VERB   VV      ROOT     xx      True    False        True   \n",
       "\n",
       "  ent_iob_ ent_type_  vector_norm  is_oov  \n",
       "0        B    PERSON     0.000000    True  \n",
       "1        O               6.573987   False  \n",
       "2        B       GPE    12.769391   False  \n",
       "3        O               6.886564   False  \n",
       "4        B       ORG    18.842812   False  \n",
       "5        O              18.138533   False  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "headers = ['text', 'lemma_', 'pos_', 'tag_', 'dep_',\n",
    "           'shape_', 'is_alpha', 'is_stop', 'has_vector',\n",
    "           'ent_iob_', 'ent_type_',\n",
    "           'vector_norm', 'is_oov']\n",
    "\n",
    "doc_data = []\n",
    "\n",
    "for token in doc:\n",
    "    token_data = [token.text, token.lemma_, token.pos_, token.tag_, token.dep_,\n",
    "                  token.shape_, token.is_alpha, token.is_stop, token.has_vector,\n",
    "                  token.ent_iob_, token.ent_type_,\n",
    "                  token.vector_norm, token.is_oov]\n",
    "    doc_data.append(token_data)\n",
    "\n",
    "pd.DataFrame(doc_data, columns=headers)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## draw dependency graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xml:lang=\"zh\" id=\"c3b1235515374dfd9468f0e90464c5a9-0\" class=\"displacy\" width=\"1100\" height=\"487.0\" direction=\"ltr\" style=\"max-width: none; height: 487.0px; color: #000000; background: #ffffff; font-family: Arial; direction: ltr\">\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"397.0\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"50\">王小明</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"50\">X</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"397.0\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"225\">在</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"225\">VERB</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"397.0\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"400\">北京</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"400\">X</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"397.0\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"575\">的</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"575\">PART</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"397.0\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"750\">清华大学</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"750\">X</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"397.0\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"925\">读书</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"925\">VERB</tspan>\n",
       "</text>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-c3b1235515374dfd9468f0e90464c5a9-0-0\" stroke-width=\"2px\" d=\"M70,352.0 C70,2.0 925.0,2.0 925.0,352.0\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-c3b1235515374dfd9468f0e90464c5a9-0-0\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">nsubj</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M70,354.0 L62,342.0 78,342.0\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-c3b1235515374dfd9468f0e90464c5a9-0-1\" stroke-width=\"2px\" d=\"M245,352.0 C245,89.5 745.0,89.5 745.0,352.0\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-c3b1235515374dfd9468f0e90464c5a9-0-1\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">case</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M245,354.0 L237,342.0 253,342.0\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-c3b1235515374dfd9468f0e90464c5a9-0-2\" stroke-width=\"2px\" d=\"M420,352.0 C420,177.0 740.0,177.0 740.0,352.0\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-c3b1235515374dfd9468f0e90464c5a9-0-2\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">nmod</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M420,354.0 L412,342.0 428,342.0\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-c3b1235515374dfd9468f0e90464c5a9-0-3\" stroke-width=\"2px\" d=\"M420,352.0 C420,264.5 560.0,264.5 560.0,352.0\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-c3b1235515374dfd9468f0e90464c5a9-0-3\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">case:dec</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M560.0,354.0 L568.0,342.0 552.0,342.0\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-c3b1235515374dfd9468f0e90464c5a9-0-4\" stroke-width=\"2px\" d=\"M770,352.0 C770,264.5 910.0,264.5 910.0,352.0\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-c3b1235515374dfd9468f0e90464c5a9-0-4\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">obl</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M770,354.0 L762,342.0 778,342.0\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "displacy.render(doc, jupyter=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div class=\"entities\" style=\"line-height: 2.5; direction: ltr\">\n",
       "<mark class=\"entity\" style=\"background: #aa9cfc; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;\">\n",
       "    王小明\n",
       "    <span style=\"font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; text-transform: uppercase; vertical-align: middle; margin-left: 0.5rem\">PERSON</span>\n",
       "</mark>\n",
       "在\n",
       "<mark class=\"entity\" style=\"background: #feca74; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;\">\n",
       "    北京\n",
       "    <span style=\"font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; text-transform: uppercase; vertical-align: middle; margin-left: 0.5rem\">GPE</span>\n",
       "</mark>\n",
       "的\n",
       "<mark class=\"entity\" style=\"background: #7aecec; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;\">\n",
       "    清华大学\n",
       "    <span style=\"font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; text-transform: uppercase; vertical-align: middle; margin-left: 0.5rem\">ORG</span>\n",
       "</mark>\n",
       "读书</div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "displacy.render(doc, jupyter=True, style='ent')"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
